<template>
  <div class="app-container"> 
    <el-form :inline="true" :model="listQuery" class="demo-form-inline">
       <i class="el-icon-search btn-search" @click="handleShowSearch()"></i>
       <div class="btn-box">
          <a
         class="el-button el-button--success el-button--medium"
        href="http://123.57.59.222:8081/api/file/payment_collection_template.xlsx"
        type="primary"
      >模版下载</a>
       <el-upload
             :action="UploadUrl()"
             :show-file-list="false"
          
            :on-success="handleImageSuccess"
            class="upload_image"
          >
            <el-button type="primary" v-show='roleName=="admin"'>导入</el-button>
          </el-upload>
      </div>
      <div  v-show="showbtns==true"  class="search-lf">
           
    <el-form-item label="战区">
        <el-select filterable
          v-model="listQuery.regionName"
         
          clearable
          @change="handleChangePro4($event)"
          placeholder="请选择"
        >
          <el-option
            v-for="item in regiosList"
            :key="item.id"
            :label="item.region"
            :value="item.region"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="省份">
        <el-select filterable v-model="listQuery.provinceName"  clearable placeholder="请选择">
          <el-option
            v-for="item in allProvinceList"
            :key="item.provinceId"
            :label="item.provinceName"
            :value="item.province"
          ></el-option>
        </el-select>
      </el-form-item>
       <el-form-item>
        <el-button  type="primary" plain  @click="getList()">查询</el-button>
         
      </el-form-item>
      </div>
     
   
     

     
    </el-form>
    <el-table
       v-loading="listLoading"  border
 height='650px'
      :data="list"
          fit
       highlight-current-row
      style="width: 100%"
    >
     
      <el-table-column align="center" label="ID">
        <template slot-scope="{row}">
          <span>{{ row.id }}</span>
        </template>
      </el-table-column>

      <el-table-column align="center" label="财年">
        <template slot-scope="{row}">
          <span>{{ row.financialYear }}</span>
        </template>
      </el-table-column>

      <el-table-column align="center" label="季度">
        <template slot-scope="{row}">
          <span>{{ row.season }}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" label="战区">
        <template slot-scope="{row}">
          <span>{{ row.regionName }}</span>
        </template>
      </el-table-column>
       <el-table-column align="center" label="省区">
        <template slot-scope="{row}">
          <span>{{ row.provinceName }}</span>
        </template>
      </el-table-column>
    
      <el-table-column align="center" label="合同金额">
          <template slot-scope="{row}">
          <span>{{ row.collectionAmount }}</span>
        </template>
      </el-table-column>
    
    
    </el-table>
  
    <pagination
      v-show="total>=20"
      :total="total"
      :page.sync="listQuery.page"
     :limit.sync="listQuery.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import {
  getPaymentList,
 
} from "@/api/base_data";
import { regiosList } from "@/api/user";
import{getProvinces} from  "@/api/supplier";
import {baseUrl2 }from '@/api/remote-search'
import Pagination from "@/components/Pagination"; 
export default {
  name: "userList",

  components: { Pagination },
  filters: {
    statusFilter(status) {
      const statusMap = {
        1: "男",
        0: "女",
      };
      return statusMap[status];
    },
  },
  data() {
    return {
      showbtns: false,
      roleName:sessionStorage.getItem('memberName'),
        regiosList: [], // 战区集合
        provinceList:[],
          total: 0,
      
      listLoading: true,
         listQuery: {
        access_token: sessionStorage.getItem("token"),
        page: 1,
        provinceName: "",
        customerName: "",
        regionName: "",
        po: "",
        pageSize: 20,
      },
      uploadUrl:'',
      list: [], }
  },
  created() {
    this.getList();
    this.getallProvinceList();
   
  },
  computed: {
    
  },
 methods: {
     getallProvinceList() {
      getProvinces().then((res) => {
        this.allProvinceList = res.data.data;
      });
    },
      handleClose(){
      this.editDisabled = false;
    },
    handleShowSearch() {
      this.showbtns = !this.showbtns;
    },
    UploadUrl(){
      return baseUrl2+'/api/file/import_payment_collection'
    },
     handleImageSuccess(file) {
      if (file.code == 200) {
        this.$message.success(file.message);
        this.getList();
      } else {
        this.$message.error(file.message);
      }
    },
        handleChangePro4(id) {
      let obj = {};
      obj = this.regiosList.find((item) => {
        return item.region === id;
      });
      this.corsesList.regionId = obj.id;
      RegionsProvince(obj.id).then((res) => {
        this.provinceList = res.data.data;
      });
    },
  
       getList() {
       this.editDisabled = false;
     
      
    regiosList().then((res) => {
        this.regiosList = res.data.data;
      });
      this.listLoading = true;
      getPaymentList(this.listQuery)
        .then((response) => {
          this.list = response.data.data.rows;
          this.total = response.data.data.total;
          this.listLoading = false;
        })
        .catch(() => {
          this.listLoading = false;
        });
    },
    
  },
};
</script>

<style scoped>
.edit-input {
  padding-right: 100px;
}
.cancel-btn {
  position: absolute;
  right: 15px;
  top: 10px;
}
</style>
